<template>
  <div>
	<!-- <router-link :to="{ path: '/admin'}">后台</router-link> -->
  <main-header></main-header>
  <search-box></search-box>
  <banner :categoriesList="categoriesList"></banner>
  <list :categoriesList="categoriesList"></list>
  </div>
</template>

<script>
  import MainHeader from '@/components/main_header'
  import SearchBox from '@/views/home/components/search'
  import Banner from '@/views/home/components/banner'
  import List from '@/views/home/components/list'
	import {getCategories} from '@/api/home/index'
  export default{
    data() {
      return {
        categoriesList:[], // 分类列表
      }
    },
    components: {
      MainHeader,SearchBox,Banner,List
    },
    methods: {
      // 获取分类列表
      async getCategories(){
        let res = await getCategories()
        if(res.code == 200){
          this.categoriesList = res.data
          // 去掉产品为空的
          let temp = []
          for(let i in this.categoriesList){
            if(this.categoriesList[i].products.length > 0){
              temp.push(this.categoriesList[i])
            }
          }
          this.categoriesList = temp
        }
        else{
          this.$message.error(res.message)
        }
      }
    },
    created() {
      this.getCategories()
    }
  }
</script>

<style>

</style>
